home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / rclesrc.10 / ircle sources / IRCNComm.p < prev    next >
Encoding:
Text File  |  1992-09-06  |  5.5 KB  |  222 lines

  1. {    ircle - Internet Relay Chat client    }
  2. {    File: IRCNComm    }
  3. {    Copyright ⌐ 1992 Olaf Titz (s_titz@iravcl.ira.uka.de)    }
  4.  
  5. {    This program is free software; you can redistribute it and/or modify    }
  6. {    it under the terms of the GNU General Public License as published by    }
  7. {    the Free Software Foundation; either version 2 of the License, or    }
  8. {    (at your option) any later version.    }
  9.  
  10. {    This program is distributed in the hope that it will be useful,    }
  11. {    but WITHOUT ANY WARRANTY; without even the implied warranty of    }
  12. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    }
  13. {    GNU General Public License for more details.    }
  14.  
  15. {    You should have received a copy of the GNU General Public License    }
  16. {    along with this program; if not, write to the Free Software    }
  17. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.    }
  18.  
  19. unit IRCNComm;
  20. { Handles numeric server messages. }
  21.  
  22. interface
  23. uses
  24.     TCPTypes, TCPStuff, TCPConnections, ApplBase, MsgWindows, {}
  25.     IRCGlobals, IRCAux, IRCChannels, IRCCommands;
  26.  
  27. function NumericComm (comm: integer; var from, target, rest: string): boolean;
  28. { Handles numeric message comm with arguments from, target, rest }
  29.  
  30. implementation
  31.  
  32. function NumericComm (comm: integer; var from, target, rest: string): boolean;
  33.     var
  34.         s: string[200];
  35.         s1, s2, s3, s4: string[80];
  36.         i: integer;
  37.     begin
  38.         NumericComm := true;
  39. { Numerics and their meanings taken mostly from IRCII. }
  40. { Where there are different formats for 2.6/2.7, this will work with 2.7 as tested. }
  41. { Here messages are sorted by type }
  42.         case comm of
  43.  
  44. { generic line }
  45.             364, { new LINKS reply }
  46.             391, { TIME reply }
  47.             372: { new MOTD reply }
  48.                 if not flushing then
  49.                     LineMsg(rest);
  50.  
  51. { generic line with from field }
  52.             200..209, 213..218: { TRACE/STATS info }
  53.                 if not flushing then begin
  54.                     s := concat(from, ': ', rest);
  55.                     LineMsg(s)
  56.                 end;
  57.  
  58. { generic error message }
  59.             401..414, { no such nick/server/channel; cannot send }
  60.             421, { unknown command }
  61.             431, 432, { bogus nick }
  62.             461, { need passwd }
  63.             472, { unknown mode }
  64.             481, 482: { no privileges }
  65.                 begin
  66.                 s := concat('*** ', rest);
  67.                 LineMsg(s);
  68.             end;
  69.  
  70. { generic error with from field }
  71.             471, 473, 474, { Cannot join }
  72.             331: { Topic bogosity }
  73.                 begin
  74.                 s := concat('*** (', from, ') ', rest);
  75.                 LineMsg(s)
  76.             end;
  77.  
  78. {╩Status information }
  79.             301:  { user is away }
  80.                 begin
  81.                 NextArg(rest, s1);
  82.                 s := concat(s1, ' is away (', rest, ')');
  83.                 Message(s)
  84.             end;
  85.             332: { Topic }
  86.                 begin
  87.                 s := concat('Topic is: ', rest);
  88.                 Message(s)
  89.             end;
  90.  
  91. { Verbose command replies }
  92.             211: { STATS L reply }
  93.                 begin
  94.                 NextArg(rest, s1);
  95.                 s := concat('**', s1, '**');
  96.                 LineMsg(s);
  97.                 s := '';
  98.                 for i := 1 to 5 do begin
  99.                     NextArg(rest, s1);
  100.                     s := stringof(s, s1 : 12);
  101.                 end;
  102.                 s := concat(s, ' ', rest);
  103.                 LineMsg(s)
  104.             end;
  105.             352:  { new WHO reply }
  106.                 if not flushing then begin
  107.                     NextArg(rest, s1);
  108.                     if s1 <> 'Channel' then begin
  109.                         NextArg(rest, s2);
  110.                         NextArg(rest, s3);
  111.                         s2 := concat(s2, '@', s3);
  112.                         NextArg(rest, s3);
  113.                         NextArg(rest, s3);
  114.                         NextArg(rest, s4);
  115.                         s := StringOf(s1 : 10, ' ', s3 : 9, s4 : 4, '  ', s2, ' (', rest, ')');
  116.                         ChannelMsg(s1, s)
  117.                     end;
  118.                 end;
  119.             353: { new NAMES reply }
  120.                 if not flushing then begin
  121.                     s := copy(rest, 3, 255);
  122.                     i := pos(' ', s);
  123.                     s1 := copy(s, 1, i - 1);
  124.                     ChannelMsg(s1, s)
  125.                 end;
  126.             311: { whois name info }
  127.                 begin
  128.                 NextArg(rest, s1);
  129.                 NextArg(rest, s2);
  130.                 NextArg(rest, s3);
  131.                 s := concat(s1, ' is ', s2, '@', s3, ' (', copy(rest, 4, 255), ')');
  132.                 Message(s)
  133.             end;
  134.             314: { whowas name info }
  135.                 begin
  136.                 NextArg(rest, s1);
  137.                 NextArg(rest, s2);
  138.                 NextArg(rest, s3);
  139.                 s := concat(s1, ' was ', s2, '@', s3, ' (', copy(rest, 4, 255), ')');
  140.                 Message(s)
  141.             end;
  142.             313: { whois operator }
  143.                 begin
  144.                 NextArg(rest, s1);
  145.                 s := concat(s1, ' ', rest);
  146.                 Message(s)
  147.             end;
  148.             319: { whois channels }
  149.                 begin
  150.                 NextArg(rest, s1);
  151.                 s := concat(s1, ' is on channels ', rest);
  152.                 Message(s)
  153.             end;
  154.             312: { whois host/server }
  155.                 begin
  156.                 NextArg(rest, s1);
  157.                 s := concat('On IRC via server ', rest);
  158.                 Message(s)
  159.             end;
  160.             317: { whois idle }
  161.                 begin
  162.                 NextArg(rest, s1);
  163.                 NextArg(rest, s2);
  164.                 s := concat('idle since ', s2);
  165.                 Message(s)
  166.             end;
  167.             321, 322: { LIST header/entry }
  168.                 if not flushing then begin
  169.                     NextArg(rest, s1);
  170.                     NextArg(rest, s2);
  171.                     s := StringOf(copy(s1, 1, 12) : 12, s2 : 4, '  ', copy(rest, 1, 60));
  172.                     LineMsg(s);
  173.                     lastWindow := nil; { save from net.terrorists with awfully long topics }
  174.                 end;
  175.             341:  { invite confirmation }
  176.                 begin
  177.                 NextArg(rest, s1);
  178.                 s := concat('Inviting ', s1, ' to channel ', rest);
  179.                 lastInvite := rest;
  180.                 ChannelMsg(rest, s)
  181.             end;
  182.             351: { Server version }
  183.                 begin
  184.                 NextArg(rest, s1);
  185.                 s := concat(from, ' runs version ', s1);
  186.                 Message(s)
  187.             end;
  188.  
  189. { End of list }
  190.             366, 323, 315, 318, 365, 219, 368: { End of list }
  191.                 begin
  192.                 flushing := false;
  193.                 UpdateStatusLine
  194.             end;
  195.  
  196. { Various errors }
  197.             433: { Nick in use }
  198.                 begin
  199.                 NextArg(rest, s1);
  200.                 s := concat('*** Nickname ', s1, ' is in use. You have to choose another.');
  201.                 LineMsg(s);
  202.             end;
  203.             463..466: { server refuses connection }
  204.                 begin
  205.                 s := concat('*** ', from, ' refuses connection: ', rest);
  206.                 LineMsg(s)
  207.             end;
  208.  
  209. { messages that generate a response }
  210.             451: { not registered }
  211.                 begin
  212.                 s := concat('*** Registration failed, trying again...');
  213.                 LineMsg(s);
  214.                 RegUser
  215.             end;
  216.  
  217.             otherwise
  218.                 NumericComm := false
  219.         end;
  220.     end;
  221.  
  222. end.